home *** CD-ROM | disk | FTP | other *** search
/ Digital Background Bonanza / Digital Background Bonanza - Disc 1.iso / pc / DBB1.swf / scripts / __Packages / mx / controls / listclasses / DataProvider.as next >
Encoding:
Text File  |  2007-03-09  |  4.6 KB  |  156 lines

  1. class mx.controls.listclasses.DataProvider extends Object
  2. {
  3.    var __ID__;
  4.    var length;
  5.    var splice;
  6.    var dispatchEvent;
  7.    var sortOn;
  8.    var reverse;
  9.    var sort;
  10.    static var mixinProps = ["addView","addItem","addItemAt","removeAll","removeItemAt","replaceItemAt","getItemAt","getItemID","sortItemsBy","sortItems","updateViews","addItemsAt","removeItemsAt","getEditingData","editField"];
  11.    static var evtDipatcher = mx.events.EventDispatcher;
  12.    static var mixins = new mx.controls.listclasses.DataProvider();
  13.    function DataProvider(obj)
  14.    {
  15.       super();
  16.    }
  17.    static function Initialize(obj)
  18.    {
  19.       var _loc4_ = mx.controls.listclasses.DataProvider.mixinProps;
  20.       var _loc6_ = _loc4_.length;
  21.       obj = obj.prototype;
  22.       var _loc3_ = 0;
  23.       while(_loc3_ < _loc6_)
  24.       {
  25.          obj[_loc4_[_loc3_]] = mx.controls.listclasses.DataProvider.mixins[_loc4_[_loc3_]];
  26.          _global.ASSetPropFlags(obj,_loc4_[_loc3_],1);
  27.          _loc3_ = _loc3_ + 1;
  28.       }
  29.       mx.events.EventDispatcher.initialize(obj);
  30.       _global.ASSetPropFlags(obj,"addEventListener",1);
  31.       _global.ASSetPropFlags(obj,"removeEventListener",1);
  32.       _global.ASSetPropFlags(obj,"dispatchEvent",1);
  33.       _global.ASSetPropFlags(obj,"dispatchQueue",1);
  34.       Object.prototype.LargestID = 0;
  35.       Object.prototype.getID = function()
  36.       {
  37.          if(this.__ID__ == undefined)
  38.          {
  39.             this.__ID__ = Object.prototype.LargestID++;
  40.             _global.ASSetPropFlags(this,"__ID__",1);
  41.          }
  42.          return this.__ID__;
  43.       };
  44.       _global.ASSetPropFlags(Object.prototype,"LargestID",1);
  45.       _global.ASSetPropFlags(Object.prototype,"getID",1);
  46.       return true;
  47.    }
  48.    function addItemAt(index, value)
  49.    {
  50.       if(index < this.length)
  51.       {
  52.          this.splice(index,0,value);
  53.       }
  54.       else if(index > this.length)
  55.       {
  56.          trace("Cannot add an item past the end of the DataProvider");
  57.          return undefined;
  58.       }
  59.       this[index] = value;
  60.       this.updateViews("addItems",index,index);
  61.    }
  62.    function addItem(value)
  63.    {
  64.       this.addItemAt(this.length,value);
  65.    }
  66.    function addItemsAt(index, newItems)
  67.    {
  68.       index = Math.min(this.length,index);
  69.       newItems.unshift(index,0);
  70.       this.splice.apply(this,newItems);
  71.       newItems.splice(0,2);
  72.       this.updateViews("addItems",index,index + newItems.length - 1);
  73.    }
  74.    function removeItemsAt(index, len)
  75.    {
  76.       var _loc3_ = new Array();
  77.       var _loc2_ = 0;
  78.       while(_loc2_ < len)
  79.       {
  80.          _loc3_.push(this.getItemID(index + _loc2_));
  81.          _loc2_ = _loc2_ + 1;
  82.       }
  83.       var _loc6_ = this.splice(index,len);
  84.       this.dispatchEvent({type:"modelChanged",eventName:"removeItems",firstItem:index,lastItem:index + len - 1,removedItems:_loc6_,removedIDs:_loc3_});
  85.    }
  86.    function removeItemAt(index)
  87.    {
  88.       var _loc2_ = this[index];
  89.       this.removeItemsAt(index,1);
  90.       return _loc2_;
  91.    }
  92.    function removeAll(Void)
  93.    {
  94.       this.splice(0);
  95.       this.updateViews("removeItems",0,this.length - 1);
  96.    }
  97.    function replaceItemAt(index, itemObj)
  98.    {
  99.       if(index < 0 || index >= this.length)
  100.       {
  101.          return undefined;
  102.       }
  103.       var _loc3_ = this.getItemID(index);
  104.       this[index] = itemObj;
  105.       this[index].__ID__ = _loc3_;
  106.       this.updateViews("updateItems",index,index);
  107.    }
  108.    function getItemAt(index)
  109.    {
  110.       return this[index];
  111.    }
  112.    function getItemID(index)
  113.    {
  114.       var _loc2_ = this[index];
  115.       if(typeof _loc2_ != "object" && _loc2_ != undefined)
  116.       {
  117.          return index;
  118.       }
  119.       return _loc2_.getID();
  120.    }
  121.    function sortItemsBy(fieldName, order)
  122.    {
  123.       if(typeof order == "string")
  124.       {
  125.          this.sortOn(fieldName);
  126.          if(order.toUpperCase() == "DESC")
  127.          {
  128.             this.reverse();
  129.          }
  130.       }
  131.       else
  132.       {
  133.          this.sortOn(fieldName,order);
  134.       }
  135.       this.updateViews("sort");
  136.    }
  137.    function sortItems(compareFunc, optionFlags)
  138.    {
  139.       this.sort(compareFunc,optionFlags);
  140.       this.updateViews("sort");
  141.    }
  142.    function editField(index, fieldName, newData)
  143.    {
  144.       this[index][fieldName] = newData;
  145.       this.dispatchEvent({type:"modelChanged",eventName:"updateField",firstItem:index,lastItem:index,fieldName:fieldName});
  146.    }
  147.    function getEditingData(index, fieldName)
  148.    {
  149.       return this[index][fieldName];
  150.    }
  151.    function updateViews(event, first, last)
  152.    {
  153.       this.dispatchEvent({type:"modelChanged",eventName:event,firstItem:first,lastItem:last});
  154.    }
  155. }
  156.